home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / HYP / T-Z / Windoids.cpt / Windoid 1.6.1 / card_12396.txt < prev    next >
Text File  |  1989-04-13  |  3KB  |  110 lines

  1. -- card: 12396 from stack: in.1
  2. -- bmap block id: 12635
  3. -- flags: 0000
  4. -- background id: 10029
  5. -- name: 
  6.  
  7.  
  8. -- part 13 (field)
  9. -- low flags: 00
  10. -- high flags: 0000
  11. -- rect: left=6 top=143 right=183 bottom=109
  12. -- title width / last selected line: 0
  13. -- icon id / first selected line: 0 / 0
  14. -- text alignment: 65535
  15. -- font id: 20
  16. -- text size: 12
  17. -- style flags: 0
  18. -- line height: 12
  19. -- part name: 
  20.  
  21.  
  22. -- part contents for background part 11
  23. ----- text -----
  24. ‚Ä¢ The function findNext(theString) goes to the next card containing the string.  It uses the find command because its so fast.  It counts the number of cards the string has been found on, and lets you do whatever you want on each card it finds.  findNext keeps track of the first card it found and tells you when you've gone all the way around the stack.
  25.  
  26. To use findNext, declare "numberFound" to be a global variable.  Set it to zero.  
  27.  
  28. FindNext("Abe") will return true if it found a new card with "Abe" on it.  It returns false if there are no more cards with "Abe".  Each time, 
  29. "numberFound" has the number of cards "Abe" was found on.
  30.  
  31. Example:  Put this into your button script.
  32.  
  33. on mouseUp
  34. --an example of using findNext()
  35. --count the number of cards with a word starting with "Abe" or whatever
  36.   global numberFound
  37.   put 0 into numberFound
  38.   repeat while findNext("Abe") --"Abe" or whatever you choose
  39.   end repeat
  40.   put "Found on" && numberFound && "cards" into message
  41. end mouseUp
  42.  
  43. Put this into your stack script.
  44.  
  45. function findNext key
  46.   --fast searching of a stack under program control.  see example.
  47.   --return true if we found a new occurance, false if done
  48.   --numberFound will have the total we have found
  49.   global numberFound, firstFound
  50.   if (numberFound = 0) or (firstFound is empty)
  51.   then return findFirst(key)
  52.  
  53.   go next card
  54.   find key
  55.  
  56.   if the result is "not found" then
  57.     put empty into firstFound
  58.     return false
  59.   end if
  60.  
  61.   if the ID of this card <> firstFound then
  62.     add 1 to numberFound
  63.     return true   --we found another occurance
  64.   else  --we wrapped around the stack
  65.     put empty into firstFound
  66.     return false
  67.   end if
  68. end findNext
  69.  
  70. function findFirst key
  71.   --only called by findNext (not called by user)
  72.   --because numberFound = 0, we know this is the first time
  73.   global numberFound, firstFound
  74.   if numberFound <> 0 then
  75.     ask "You must put 0 into numberFound before calling findNext()"¬¨with "OK"
  76.     return false
  77.   end if
  78.  
  79.   find key
  80.  
  81.   if the result is "not found" then
  82.     put empty into firstFound
  83.     return false
  84.   else   --we found it
  85.     put the ID of this card into firstFound
  86.     put 1 into numberFound
  87.     return true
  88.   end if
  89. end findFirst
  90.  
  91. You can put findNext() and its subroutine, findFirst(), into your home script.  If you have stricter conditions on the cards you want to find, do your tests on each card that findNext finds.
  92. Ô£ø
  93.  
  94. -- part contents for background part 17
  95. ----- text -----
  96. Find Next:
  97.  
  98. -- part contents for background part 18
  99. ----- text -----
  100. ‚Ä¢ by
  101. Ted Kaehler
  102.  
  103. -- part contents for card part 13
  104. ----- text -----
  105. civilized searching controlled by
  106. your script
  107.  
  108. -- part contents for background part 19
  109. ----- text -----
  110. volume 1 ‚Ä¢  number  6  ‚Ä¢  card 7  ‚Ä¢